home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / zugabe / va45 / visual45 / v_aext / filesrch.41 next >
Text File  |  1996-06-22  |  6KB  |  284 lines

  1. ******************************************************************
  2. * Module de recherche récursive de fichiers * (c) Wax 30/12/1993 *
  3. * Adapté au V 4.0 la 21/06/96
  4. ******************************************************************
  5. ;    Entrée :    a0.l : chemin de départ : U:\PATH
  6. ;        a1.l : pointeur sur un masque multiple terminé par 0 0 max 100 car
  7. ;        exemple : *.F?D 0 AZERTY.* 0 *.MOD 0 0
  8. ;        a2.l : adresse de la routine où sauter
  9. ;        d0.w : 0 recherche normale, 1 recursive
  10. ;    Sortie :    d7.w : 0 =OK -2=bad path -1=user stop(vous avez rendu d0<0)
  11. ;
  12. ;    Appel de votre routine :
  13. ;    Entrée :    a0 : pathname du fichier U:\PATH
  14. ;    Sortie :    faites un rts avec d0=0 = continue; d0=-1 arrête là
  15.  
  16. SEARCH_FILE_RECURSIVELY:
  17.     movem.l a0-a2,FILESEARCH_PATH
  18.     move d0,FILESEARCH_MODE
  19.  
  20.     FGETDTA
  21.     move.l d0,FILESEARCH_SAVE_DTA
  22.  
  23.     clr d0
  24.     move.b ([FILESEARCH_PATH]),d0
  25.     sub.b #'A',d0
  26.     DSETDRV d0
  27.  
  28.     move.l FILESEARCH_PATH,a0
  29.     lea 2(a0),a0
  30.     DSETPATH (a0)
  31.     tst d0
  32.     bne .end_with_erreur
  33.  
  34.     move.l FILESEARCH_PATH,a0
  35.     lea 2(a0),a0
  36.     lea FILESEARCH_CURRENT_PATH,a1
  37.     bsr .copy_for_next
  38.     lea FILESEARCH_CURRENT_PATH,a0
  39.     bsr .put_anti_at_end
  40.  
  41.     move.l FILESEARCH_MASK,a0    ; est-ce un masque ou un nom ?
  42. .retest:    tst.b (a0)
  43.     beq.s .its_not_mask
  44.     cmp.b #'*',(a0)
  45.     beq.s .its_mask
  46.     cmp.b #'?',(a0)+
  47.     beq.s .its_mask
  48.     bra.s .retest
  49.  
  50. .its_not_mask:
  51.     move.l FILESEARCH_MASK,a0
  52.     DSETPATH (a0)
  53.     tst d0
  54.     bne.s .not_a_dir
  55.  
  56.     lea FILESEARCH_MASK_2POINTS,a0
  57.     DSETPATH (a0)
  58.  
  59.     move.l FILESEARCH_MASK,a0
  60.     lea FILESEARCH_NEXT_CD_DIR,a1
  61.     bsr .copy_for_next
  62.  
  63.     move.l #FILESEARCH_MASK_EVERYTHING,FILESEARCH_MASK
  64.     bra.s .continuons
  65.  
  66. .its_mask:
  67. .not_a_dir:    move.w #'.'*256,FILESEARCH_NEXT_CD_DIR
  68.  
  69. .continuons:bsr.s .find_recurse
  70.  
  71.     save.w d0
  72.     move.l FILESEARCH_SAVE_DTA,a0
  73.     FSETDTA (a0)
  74.     load.w d7
  75.     rts
  76.  
  77. .end_with_erreur:
  78.     moveq #-2,d7
  79.     rts
  80.  
  81.  
  82. ;---------------------------------------------------------------------------
  83. for_link=44+2
  84.  
  85. .find_recurse:
  86.     link a6,#-for_link        ; dans nom : le chemin
  87.     move.l a7,a5
  88.  
  89.     clr.w 44(a5)
  90.     cmp.w #'.'*256,FILESEARCH_NEXT_CD_DIR
  91.     bne.s .pas_root
  92.     move.w #1,44(a5)        ; pour pas faire cd .. sur root
  93. .pas_root:
  94.  
  95.     DSETPATH FILESEARCH_NEXT_CD_DIR
  96.     tst d0
  97.     bne .please_stop_here        ; dès fois que ... l'util soit sévèrement burné
  98.  
  99.     tst 44(a5)
  100.     bne.s .no_no
  101.     lea FILESEARCH_NEXT_CD_DIR,a0
  102.     bsr .add_to_path
  103.     lea FILESEARCH_CURRENT_PATH,a0
  104.     bsr .put_anti_at_end
  105. .no_no:
  106.     bsr .fset_dta
  107.     FSFIRST #%010011,FILESEARCH_MASK_EVERYTHING    ; tous les dirs + fichiers (p.67)
  108.     tst d0
  109.     bne .no_dir_here
  110.  
  111. .next_dir:    cmp.b #'.',30(a5)        ; ne marche pas sous Unix
  112.     beq.s .next_research
  113.  
  114.     btst.b #4,21(a5)
  115.     beq.s .its_a_file
  116.  
  117.     tst FILESEARCH_MODE        ; récursif ?
  118.     beq.s .next_research
  119.  
  120.     lea 30(a5),a0
  121.     lea FILESEARCH_NEXT_CD_DIR,a1
  122.     bsr .copy_for_next
  123.  
  124.     save.l a5
  125.     bsr .find_recurse
  126.     load.l a5
  127.     tst d0
  128.     bmi .please_stop_here
  129.     bra.s .next_research
  130.  
  131. .its_a_file:bsr .compare_to_mask
  132.     tst d0
  133.     bmi.s .next_research
  134.  
  135.     bsr.s .make_name
  136.     save.l a5-a6
  137.     lea FILESEARCH_RETURN_NAME,a0
  138.     jsr ([FILESEARCH_ROUTINE])
  139.     load.l a5-a6
  140.     tst d0
  141.     bmi.s .please_stop_here
  142.  
  143.     clr d0
  144.     move.b ([FILESEARCH_PATH]),d0
  145.     sub #'A',d0
  146.     DSETDRV d0
  147.     DSETPATH FILESEARCH_CURRENT_PATH        ; dès fois que le GROC
  148.  
  149. .next_research:
  150.     bsr.s .fset_dta
  151.     FSNEXT
  152.     tst d0
  153.     beq .next_dir
  154. .no_dir_here:
  155.  
  156.     tst.w 44(a5)
  157.     bne.s .its_root
  158.     bsr .sub_one_path
  159.     DSETPATH FILESEARCH_MASK_2POINTS
  160.  
  161. .its_root:
  162.     clr d0
  163.  
  164. .please_stop_here:
  165.     unlk a6
  166.     rts
  167.  
  168. .fset_dta:    FSETDTA (a5)
  169.     rts
  170.  
  171. .make_name:    lea FILESEARCH_RETURN_NAME,a1
  172.     move.b ([FILESEARCH_PATH]),(a1)+        ; drive
  173.     move.b #':',(a1)+
  174.     lea FILESEARCH_CURRENT_PATH,a0        ; path
  175.     bsr .copy_for_next
  176.  
  177.     lea -1(a1),a1
  178.     lea 30(a5),a0
  179.     bsr .copy_for_next        ; filename
  180.     rts
  181.  
  182. .compare_to_mask:
  183.     clr d0
  184.     move.l FILESEARCH_MASK,a0
  185. .one_more_chance:
  186.     lea 30(a5),a1
  187.  
  188. .rec:    tst.b (a0)        ; a0:mask , a1:=nom
  189.     beq.s .end_of_mask
  190.     tst.b (a1)
  191.     beq.s .end_not_ok    ; plus de comparaison mais encore du masque NOT OK
  192.     cmp.b #'*',(a0)    ; car on a défilé tout le nom avec la 1ère *
  193.     beq.s .its_etoile
  194.     cmp.b #'?',(a0)
  195.     beq.s .its_interro
  196.  
  197.     cmp.b (a0)+,(a1)+
  198.     beq.s .rec
  199.  
  200. .end_not_ok:
  201.  
  202. .f0:    tst.b (a0)+    ; si comparaison pas cool avnt la fin du mask
  203.     bne.s .f0
  204.     lea -1(a0),a0
  205.  
  206.     tst.b 1(a0)
  207.     beq.s .last_mask
  208.     lea 1(a0),a0
  209.     bra.s .one_more_chance
  210.  
  211. .last_mask:    move.w #-1,d0
  212. .end_ok_cmp:    rts
  213.  
  214. .end_of_mask:tst.b (a1)
  215.     beq.s .end_ok_cmp    ; plus de masque et pas sorti : OK
  216.             ; si fin du nom à comparer aussi
  217.     bra.s .end_not_ok    ; sinon (ex. : *.PR -> TXT.PRG)
  218.  
  219. .its_etoile:    lea 1(a0),a0
  220.     move.b (a0),d1
  221. .find:    tst.b (a1)
  222.     beq.s .rec        ; fin du nom de fichier atteint
  223.     cmp.b (a1)+,d1
  224.     bne.s .find
  225.     lea -1(a1),a1    ; si c'était 0, il faut le comparer...
  226.     bra.s .rec
  227.  
  228. .its_interro:
  229.     lea 1(a0),a0
  230.     lea 1(a1),a1
  231.     bra.s .rec
  232.  
  233. ;---------------------------------------------------------------------------
  234.  
  235. .add_to_path:lea FILESEARCH_CURRENT_PATH,a1
  236. .find0:    tst.b (a1)+
  237.     bne.s .find0
  238.     lea -1(a1),a1        ; sur le 0
  239.  
  240. .copy_for_next:
  241.     COPY_STRING_0 a0,a1
  242.     rts
  243.  
  244. .sub_one_path:
  245.     lea FILESEARCH_CURRENT_PATH,a0
  246. .find1:    tst.b (a0)+
  247.     bne.s .find1
  248.     lea -2(a0),a0
  249. .not_anti:    cmp.b #'\',-(a0)
  250.     bne.s .not_anti
  251.     clr.b 1(a0)
  252.     rts
  253.  
  254. .put_anti_at_end:
  255. .not_0:    tst.b (a0)+
  256.     bne.s .not_0
  257.     cmp.b #'\',-2(a0)
  258.     beq.s .already    ; si root
  259.     move.b #'\',-1(a0)
  260.     clr.b (a0)
  261. .already:    rts
  262. ;---------------------------------------------------------------------------
  263.  
  264.     DATA
  265. FILESEARCH_MASK_EVERYTHING:    dc.b '*.*',0
  266. FILESEARCH_MASK_2POINTS:    dc.b '..',0
  267.     even
  268.  
  269.     BSS
  270. FILESEARCH_PATH:    ds.l 1    ; chemin ou commencer la recherche
  271. FILESEARCH_MASK:    ds.l 1    ; masque de recherche
  272. FILESEARCH_ROUTINE:    ds.l 1    ; ad. routien où sauter
  273. FILESEARCH_MODE:    ds.w 1    ; doit-on faire une recherche récursive (0=non)
  274.  
  275. FILESEARCH_SAVE_DTA:    ds.l 1
  276. FILESEARCH_CURRENT_PATH:ds.b GWVA_MAX_PATH_LENGTH
  277.     ; path pour construire les noms de fichier
  278.     ; path courant durant le traitement récursif...
  279.  
  280. FILESEARCH_NEXT_CD_DIR:    ds.b 8+1+3+1    ; chemin où rentrer pour le prochain appel récursif
  281. FILESEARCH_RETURN_NAME:    ds.b GWVA_MAX_PATH_LENGTH    ; nom renvoyé aux abonés traiteurs
  282.  even
  283.     TEXT
  284.